package org.csu.pm.controller;

import org.csu.pm.annotation.AuthUser;
import org.csu.pm.common.BaseResponse;
import org.csu.pm.entity.BookInfo;
import org.csu.pm.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/book")
public class BookController {
    @Autowired
    BookService bookService;

    // 根据id查询预约信息
    @GetMapping(value = "/book_info/{id}")
    public BaseResponse<?> bookInfo(@PathVariable String id, @AuthUser String userId) {
        return bookService.getBookInfo(Long.valueOf(id));
    }

    // 根据userId查询预约信息
    @GetMapping(value = "/user/{user_id}")
    public BaseResponse<?> getBookInfoByUserId(@PathVariable("user_id") @AuthUser String userId) {
        return bookService.getBookInfoListByUserId(Long.valueOf(userId));
    }

    // 根据roomId查询预约信息
    @GetMapping(value = "/room/{room_id}")
    public BaseResponse<?> getBookInfoByRoomId(@PathVariable("room_id") String room_id, @AuthUser String userId) {
        return bookService.getBookInfoListByRoomId(room_id);
    }

    // 查询所有的预约信息
    @GetMapping("/book_infos")
    public BaseResponse<?> getAllBookInfos(@AuthUser String userId) {
        return bookService.getBookInfoList();
    }

    // 新增预约信息
    @PostMapping("")
    public BaseResponse<?> addBookInfo(@AuthUser String userId, @RequestBody BookInfo bookInfo) {
        return bookService.insertBookInfo(bookInfo);
    }

    // 删除预约信息
    @DeleteMapping("/book_info/{id}")
    public BaseResponse<?> addBookInfo(@AuthUser String userId, @PathVariable String id) {
        return bookService.deleteBookInfo(id);
    }

    // 修改预约信息
    @PutMapping("/book_info/{id}")
    public BaseResponse<?> updateBookInfo(@AuthUser String userId, @RequestBody BookInfo bookInfo) {
        return bookService.updateBookInfo(bookInfo.getId().toString(), bookInfo);
    }

}